package com.spring.security.service;

import com.auth0.jwt.exceptions.JWTCreationException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.spring.security.entity.User;

/**
 * @author HouKunLin
 */
public interface JwtService {
    /**
     * 签名生成 JWT token
     *
     * @param user 用户信息
     * @return
     * @throws JWTCreationException
     */
    String sign(User user) throws JWTCreationException;

    /**
     * 签名生成 JWT token
     *
     * @param user   用户信息
     * @param secret 密码
     * @return
     * @throws JWTCreationException
     */
    String sign(User user, String secret) throws JWTCreationException;

    /**
     * 验证 token
     *
     * @param token token
     * @return
     */
    boolean verify(String token);

    /**
     * 验证 token
     *
     * @param token  token
     * @param secret 密码
     * @return
     */
    boolean verify(String token, String secret);

    /**
     * 解密 Token
     *
     * @param token token
     * @return
     * @throws JWTVerificationException
     */
    DecodedJWT decodedJWT(String token) throws JWTVerificationException;

    /**
     * 解密 Token
     *
     * @param token  token
     * @param secret 密码
     * @return
     * @throws JWTVerificationException
     */
    DecodedJWT decodedJWT(String token, String secret) throws JWTVerificationException;
}
